﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ShortLink.Common.Results;
using SL_Account.Services;
using SL_Account.Services.Impl;

namespace SL_Account.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class NotifyController : ControllerBase
    {
        private readonly IHttpContextAccessor accessor;
        private readonly INotifyService notifyService;

        public NotifyController(IHttpContextAccessor accessor, INotifyService notifyService)
        {
            this.accessor = accessor;
            this.notifyService = notifyService;
        }

        [HttpGet("Captcha")]
        public async Task<IActionResult> GetCaptcha() 
        {
            var jsonData = await notifyService.GenerateCode();
            var codeImage = jsonData.Data as byte[];
            return File(codeImage, "image/png");
        }


        [HttpGet("Notify")]
        public async Task<JsonData> SendNotifyCode(string to,string key) 
        {
            return await notifyService.SendEmail(to,key);
        }
    }
}
